#include<bits/stdc++.h>
using namespace std;

char a[1001][1001];
int ans[1001][1001];
int cnt;
int m, n;
bool vis[1001][1001];

void dfs(int x, int y) {
	if (x < 1 || y < 1 || x > m || y > n || vis[x][y])
		return ;
	if (a[x][y] == '*') {
		a[x][y] = '1';
		ans[x][y] = cnt;
	}

//		a[x][y] = (char)(cnt+'0');
	else
		return ;
	vis[x][y] = 1;
	dfs(x - 1, y);
	dfs(x, y - 1);
	dfs(x + 1, y);
	dfs(x, y + 1);
}

int main() {
	int t;
	cin >> t;
	while (t--) {
		memset(vis, 0, sizeof vis);
		cin >> m >> n;
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				cin >> a[i][j];
				if (a[i][j] == '#')
					ans[i][j] = 0;
			}
		}

		cnt = 1;
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				if (a[i][j] == '*') {
					dfs(i, j);
					cnt++;
					if (cnt == 25)
						cnt = 1;
				}
			}
		}
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				cout << ans[i][j] << " ";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

